package com.xiaolei.lib.annotation.translators;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

import com.xiaolei.lib.Activity.IActivity;
import com.xiaolei.lib.Activity.bean.AnnotationWrape;
import com.xiaolei.lib.Activity.bean.ContextClickListener;
import com.xiaolei.lib.Activity.bean.OnClickHolder;
import com.xiaolei.lib.annotation.Bind;
import com.xiaolei.lib.annotation.setOnClick;
import com.xiaolei.lib.annotation.factory.BeanFactory;
import com.xiaolei.lib.core.ITranslator;

import android.view.View;

public class setOnclickTranslator implements ITranslator
{

	@Override
	public void execute(Field field, IActivity activity, AnnotationWrape annotation)
	{
		// TODO Auto-generated method stub

	}

	@Override
	public void execute(final Method method, final IActivity activity, AnnotationWrape annotation)
	{
		int ids[] = null;
		ContextClickListener listener = BeanFactory.getInstance(ContextClickListener.class);
		setOnClick sClick = annotation.get(setOnClick.class);
		Bind bind = annotation.get(Bind.class);
		
		if (sClick != null)
		{
			ids = sClick.value();
		}else if (bind != null) 
		{
			ids = new int[]{bind.value()};
		}
		if(ids == null) return;
		
		for (int id : ids)
		{
			final View view = activity.findViewByID(id);
			activity.registClickView(view);
			OnClickHolder holder = new OnClickHolder(activity,method);
			listener.registClickListener(view, holder);
		}
	}

	@Override
	public void execute(Class<?> type, IActivity activity, AnnotationWrape annotation)
	{
		// TODO Auto-generated method stub

	}

}
